function object2Array(myObject) 
{
	var myArray = null;
	if(myObject != null)
	{
		if(myObject.length != null)
		{
			return myObject;
		}
		else
		{
			myArray = new Array();
			myArray[0] = myObject;
		}
	}
	return myArray;
} 

//把null值转换为空格字符或在字符串前加空格
function null2empty2(obj)
{
	if(obj == null || obj == "")
	{
		return " ";
	}
	else
	{
		return obj;
	}
}

function null2emptyHtml(obj)
{
	if(obj == null || obj == "")
	{
		return "&nbsp;";
	}
	else
	{
		return obj;
	}
}

function null2empty(obj)
{
	if(obj == null || obj == "")
	{
		return " ";
	}
	else
	{
		return " " + obj;
	}
}

function checkError(code)
{
	if(code == 110 || code == 119)
	{
		return true;
	}
	return false;
}




function createDivForList(entId, lon, lat)
{
	var div = document.createElement("div");
	div.id = "divId"+entId;
    div.onmouseover = function()
    {

        div.className=div.className+"over";
    }
    
    div.onmouseout = function()
    {
       var reg = /over/gi;
       div.className= div.className.replace(reg,"");
    }
    
    div.onclick = function()
    {
       displayBaseInfo(entId, lon, lat);
   }
   
   return div;
}

function deleteInfo(idName, id, target, areaName, areaId, callback) 
{
    if(!confirm("你确定要删除此信息吗?  "))
    {
    	return;
    }
    var url = target;
    var parm = "?"+ idName +"=" + id + "&actionType=4&"+ areaName +"="+ areaId;
    jQuery.ajax({
        url: url + parm,
        type: 'GET',
        dataType: 'xmldocument',
        error: function(request, error){
            alert('Load Error');
        },
        success: function(xml)
        {
            var returnCode = $.xml2json(xml);
            if (returnCode == "0") 
			{
				alert(" 信息删除成功!       ");
				
				if(callback != null)
				{
					callback(id);
				}
				else
				{
					location.reload();
				}
			}
            else
            {
            	 alert("信息删除失败，请确认输入是否正确！");
            }
            return returnCode;
        }
    });
}


function printDiv(div, title){
	var headStr = "<html><head><title></title></head><body>";
	var reportTitle = "<div class='reportTitle'>" + title + " </div> <br />";
	var newBodyStr = document.getElementById(div).innerHTML;
	var oldBodyStr = document.body.innerHTML;
	var footStr = "</body></html>";
	document.body.innerHTML = headStr + reportTitle + newBodyStr +footStr;

	window.print();
	document.body.innerHTML = oldBodyStr;
	return false;
}

function isInArray(arrayObj, value)
{
	var returnValue = -1;
	if(arrayObj != null && arrayObj.length != null && value != null)
	{
		for(var i=0; i<arrayObj.length; i++)
		{
			if(arrayObj[i] == value)
			{
				returnValue = i;
				break;
			}
		}
	}
	
	return returnValue;
}

function code2Name(code, types)
{
	if(isNotEmpty(code) && types != null)
	{
		types = object2Array(types);
		for(var i=0;i<types.length;i++)
		{
			if(types[i]["code"] == code)
			{
				return null2empty(types[i]["name"]);
			}
		}
	}
}


function ajaxPost(myUrl, formId, onSuccess)
{
    if(isNotEmpty(myUrl))
    {
    	jQuery.ajax({
		    url: myUrl,
		    type: 'POST',
		    dataType: 'json',
			data:$("#"+formId).serialize(),
	        error: function(request, error){ 
	            alert('Load Error');
	        },
	        success: function(json)
	        {
	            //var json = $.xml2json(xml);
	            if(onSuccess != null)
	            {
	            	onSuccess(json);
	            }
	        }
    	});
    }
}

function ajaxGet(myUrl, onSuccess)
{
    if(isNotEmpty(myUrl))
    {
    	jQuery.ajax({
	        url: myUrl,
	        type: 'GET',
	        dataType: 'json',
	        error: function(request, error){ 
	            alert('Load Error');
	        },
	        success: function(json)
	        {
	           // var json = $.xml2json(xml);
	            if(onSuccess != null)
	            {
	            	onSuccess(json);
	            }
	        }
    	});
    }
}

function ajaxPut(myUrl, onSuccess)
{
    if(isNotEmpty(myUrl))
    {
    	jQuery.ajax({
	        url: myUrl,
	        type: 'PUT',
	        dataType: 'json',
	        error: function(request, error){ 
	            alert('Load Error');
	        },
	        success: function(json)
	        {
	            //var json = $.xml2json(xml);
	            if(onSuccess != null)
	            {
	            	onSuccess(json);
	            }
	        }
    	});
    }
}

function ajaxDelete(myUrl, onSuccess)
{
    if(isNotEmpty(myUrl))
    {
    	jQuery.ajax({
	        url: myUrl,
	        type: 'DELETE',
	        dataType: 'json',
	        error: function(request, error){ 
	            alert('Load Error');
	        },
	        success: function(json)
	        {
	            //var json = $.xml2json(xml);
	            if(onSuccess != null)
	            {
	            	onSuccess(json);
	            }
	        }
    	});
    }
}

function fillImg(elementId, imgUrl, width, height)
{
	if(isNotEmpty(elementId) && $("#"+elementId)[0] != null)
	{
		$("#"+elementId)[0].innerHTML = "&nbsp;";
		if(isNotEmpty(imgUrl))
		{
	 		var imgWidthHeight = isNotEmpty(width) ? " width='"+width+"' " : " width='100' ";
	 		imgWidthHeight = isNotEmpty(height) ? imgWidthHeight+ " height='"+height+"' " : imgWidthHeight;
	 		
	 		var imagesUrl = imgUrl.split(";");
		    if(imagesUrl != null && imagesUrl.length != null)
		    {
		    	$("#"+elementId)[0].innerHTML = "";
		    	for(var j=0; j<imagesUrl.length; j++)
		        {
			        if(isNotEmpty(imagesUrl[j]))
					{
						$("#"+elementId)[0].innerHTML += "<div><a href='../"+imagesUrl[j]+"' target='_blank'><img border='0' "+imgWidthHeight+" src='../"+imagesUrl[j]+"'/><a></div><br/>";
					}
		     	}
		    }
		}
	}
}

function fillSelect(selectId, code)
{
	if(isNotEmpty(code))
	{
		var selectObj = $("#"+selectId)[0];
		for (var i=0; i<selectObj.options.length; i++)
		{
			if (selectObj.options[i].value == code)
			{
				selectObj.options[i].selected = true;
				break;
			}
		}
	}
}

function fillInfo(objInfo, startString, endString)
{
	if(isNotEmpty(objInfo))
	{
		for(var i in objInfo)
	    {
			if(isNotEmpty(i))
			{
				var idString = isNotEmpty(startString) ?  startString+i : i;
				idString = isNotEmpty(endString) ?  idString + endString : idString;
				
				var obj = $("#"+idString)[0];
				if (obj != null) 
				{
					if(isNotEmpty(obj.type))
					{
						obj.value = null2empty(objInfo[i]);
					}
					else 
					{
						obj.innerText = null2empty(objInfo[i]);
					}
				}
			}
		}
	}
}

function isNotEmpty(obj)
{
	var flag = false;
	if(obj != null && obj != "")
	{
		flag = true;
	}
	
	return flag;
}



function deleteTable(tableObj, beginRow)
{
	if(beginRow == null)
	{
		beginRow = 2;
	}
	
	if(tableObj != null)
	{
		var length = tableObj.rows.length;
		for(var i=length-1; i>=beginRow-1; i--)
		{
			 tableObj.deleteRow(i);
		}
	}
}


